const {
  $util,
} = getApp();
Page({
  data: {
    page: 1,
    list: [],
    hasMore: true,
    id: '', // ''考察开始后仅需上传一篇考察报告即可  ，有值为考察开始后某时间段内每天都需要上传一篇考察报告
  },
  onLoad(ops) {
    this.setData(ops);
    wx.setNavigationBarTitle({
      title: '党建考察',
    });
  },
  onShow() {
    this.loadList();
  },
  loadList() {
    let { id = '' } = this.data;
    if (id === '') {
      $util.request({
        url: 'entry/wxapp/partyman.investigate.gettasklist',
        data: {
          page: this.data.page,
          version: 1,
        },
        success: (res) => {
          let list = res.list;
          if (this.data.page > 1) {
            list = [...this.data.list, ...list];
          }
          this.setData({
            list,
            canshow: res.canshow,
            hasMore: res.list.length > list.length,
            page: res.list.length > list.length ? this.data.page + 1 : this.data.page,
            loaded: true,
          });
        },
      });
    } else {
      $util.request({
        url: 'entry/wxapp/partyman.investigate.getreportlist',
        data: {
          tid: id,
        },
        success: (res) => {
          this.setData({
            list: res.data,
            loaded: true,
            hasMore: false,
          });
        },
      });
    }
  },
  onReachBottom() {
    this.data.id === '' && this.data.hasMore && this.loadList();
  },
  goReport(e) {
    let { id, tid, status } = e.currentTarget.dataset;
    if (Number(status) > 3) {
      wx.showToast({
        title: status === 4 ? '已超期' : '未开始',
        icon: 'none',
      });
    } else {
      wx.navigateTo({
        url: `/ws_party_const/pages/investigate/report?id=${id}&tid=${tid}&status=${status}`,
      });
    }
  },
});
